package acwing.差分;

import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

/**
 * 粉刷栅栏
 *
 * @author yang
 * @date 2022/1/16
 */
public class 粉刷栅栏 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Map<Integer,Integer> m = new TreeMap<>( (a, b)-> a-b);
        int n = sc.nextInt();
        int now = 0;
        while (n-- != 0) {
            int dis = sc.nextInt();
            if(sc.next().equals("R")) {
                m.put(now,m.getOrDefault(now,0) +1);
                now +=dis;
                m.put(now,m.getOrDefault(now,0) -1);
            } else {
                m.put(now,m.getOrDefault(now,0) -1);
                now -=dis;
                m.put(now,m.getOrDefault(now,0) +1);
            }
        }
        int num = 0, pro = 0, ans = 0;
        for (int i : m.keySet()) {
            if (num >= 2) ans += i - pro;
            num += m.get(i);
            pro = i;
        }
        System.out.println(ans);
    }
}
